package com.wwwarehouse.taskcenter.custom_view;

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wwwarehouse.taskcenter.R;
import com.wwwarehouse.taskcenter.bean.KeyBoardItemBean;

import java.util.List;

/**
 * Created by clannad.shao on 2017/11/15.
 * Description:
 */
public class CarNumAdapter extends BaseAdapter {

    private Context mContext;
    private List<KeyBoardItemBean> mList;
    private int initSelection;

    public CarNumAdapter(Context mContext, @NonNull List<KeyBoardItemBean> mList, int initSelection) {
        this.mList = mList;
        this.mContext = mContext;
        this.initSelection = initSelection;
    }

    public void setInitSelection(int pos){
        this.initSelection = pos;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.task_center_carnum_keyboard_item, null);
            viewHolder = new ViewHolder();
            viewHolder.idKeyBoardItemTv = (TextView) convertView.findViewById(R.id.idKeyBoardItemTv);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        if(position == initSelection){
            viewHolder.idKeyBoardItemTv.setBackground(mContext.getResources().getDrawable(R.drawable.task_center_keyboard_itemback_blue));
            viewHolder.idKeyBoardItemTv.setTextColor(Color.parseColor("#ffffff"));
        }else{
            viewHolder.idKeyBoardItemTv.setBackground(mContext.getResources().getDrawable(R.drawable.task_center_keyboard_itemback));
            viewHolder.idKeyBoardItemTv.setTextColor(Color.parseColor("#000000"));
        }

        viewHolder.idKeyBoardItemTv.setText(mList.get(position).getName());
        return convertView;
    }

    class ViewHolder {
        TextView idKeyBoardItemTv;
    }
}
